package com.guyu.plugin.satoken.service;

import com.google.common.collect.Maps;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import java.util.Map;

public class SaTokenHelper implements ApplicationContextAware {

    private static final Map<String, LoginUserService> LOGIN_USER_SERVICE_MAP = Maps.newHashMap();

    public LoginUserService getLoginUserService(String loginType) {
        return LOGIN_USER_SERVICE_MAP.get(loginType);
    }


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, LoginUserService> map = applicationContext.getBeansOfType(LoginUserService.class);
        map.forEach((key, value) -> LOGIN_USER_SERVICE_MAP.put(value.getLoginType(), value));
    }
}
